//
//  ModifyPhoneNumVC.m
//  SDHuiYuShoping
//
//  Created by luojiao on 2017/6/22.
//  Copyright © 2017年 luojiao. All rights reserved.
//

#import "ModifyPhoneNumVC.h"

@interface ModifyPhoneNumVC ()
{
    int number;
}
@end

@implementation ModifyPhoneNumVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置返回按钮
    [self.backButton setImage:[UIImage imageNamed:@"back_white_btn"] forState:UIControlStateNormal];
    [self.backButton setImageEdgeInsets:UIEdgeInsetsMake(0, -50, 0, 0)];
    [self.backButton setTitle:@"返回" forState:UIControlStateNormal];
    [self.backButton setTitleEdgeInsets:UIEdgeInsetsMake(0, -40, 0, 0)];
    
    [self.sendButton setTitle:@"获取验证码" forState:UIControlStateNormal];
    self.sendButton.backgroundColor = [FRUtils colorWithHexString:@"dc0000"];
    number = 60;

    self.numtextField.delegate = self;
    self.codeTextField.delegate = self;
    self.errorLabel.hidden = YES;
    self.titleLabel.text = self.titleName;
    
    self.numBg.image = [UIImage imageNamed:@"input_bg"];
    self.codeBg.image = [UIImage imageNamed:@"input_bg"];
    [self.inputButton setBackgroundImage:[UIImage imageNamed:@"change_bg"] forState:UIControlStateNormal];
    [self.inputButton setTitle:@"提交" forState:UIControlStateNormal];
    [self.inputButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -ButtonClick

- (IBAction)backButtonClick:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)sendButtton:(id)sender
{
    if ([FRUtils isMobileNumber:self.numtextField.text])
    {
        NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(sendButtonSet:) userInfo:nil repeats:YES];
        [timer fire];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"错误提示！" message:@"请正确输入手机号！" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }

}

- (IBAction)inputButton:(id)sender {
}


- (void)sendButtonSet:(NSTimer*)timers
{
    if (number == -1)
    {
        self.sendButton.enabled = YES;
        number = 60;
        [timers invalidate];
        timers = nil;
    }
    else
    {
        self.sendButton.enabled = NO;
        [self.sendButton setTitle:[NSString stringWithFormat:@"%d s",number] forState:UIControlStateNormal];
        number--;
    }
    
}

#pragma mark -UITextFieldDelegate

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.numtextField resignFirstResponder];
    [self.codeTextField resignFirstResponder];
    [self.view endEditing:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
